// Tests scoreFor()

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

// set BOUNDARY_TEST to 0 to exclude boundary test cases.
#define BOUNDARY_TEST 0

int getCost(int cardNumber);

int main(int argc, char *argv[]) {
    int i;
    int seed = 1000;
    int numPlayer = 2;
    int maxBonus = 10;
    int p, r, handCount;
    int bonus;
    int k[10] = {adventurer, council_room, feast, gardens, mine
        , remodel, smithy, village, baron, great_hall};
    struct gameState G;
    int maxHandCount = 5;
    int cursePoints = -1;
    int estatePoints = 1;
    int gardenPoints = 0;
    
    // arrays of all coppers, silvers, and golds
    int coppers[MAX_HAND];
    int silvers[MAX_HAND];
    int golds[MAX_HAND];
    int curseArray[MAX_HAND];
    int estateArray[MAX_HAND];
    int gardensArray[MAX_HAND];
    for (i = 0; i < MAX_HAND; i++)
    {
        curseArray[i] = curse;
        estateArray[i] = estate;
        gardensArray[i] = gardens;
    }
    
    for (i = 0; i < MAX_HAND; i++)
    {
        coppers[i] = copper;
        silvers[i] = silver;
        golds[i] = gold;
    }
    
    for (p = 0; p < numPlayer; p++)
    {
        printf ("TESTING getCost():\n\n");
        for (handCount = 1; handCount <= maxHandCount; handCount++)
        {

// Test for curse points
#if (NOISY_TEST == 1)
			printf("Player %d with %d curse card(s).\n", p, handCount);
#endif
            memset(&G, 23, sizeof(struct gameState));   // clear the game state
            r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
            G.handCount[p] = handCount;                 // set the number of cards on hand
            memcpy(G.hand[p], curseArray, sizeof(int) * handCount); // set all the cards to curses

#if (NOISY_TEST == 1)
            printf("Score = %d\n", scoreFor(p,&G));
            printf("Expected = %d\n\n", handCount * cursePoints);
#endif
            assert(scoreFor(p,&G) == handCount * cursePoints);
            
// Test for estate points
#if (NOISY_TEST == 1)
			printf("Player %d with %d estate card(s).\n", p, handCount);
#endif
            memset(&G, 23, sizeof(struct gameState));   // clear the game state
            r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
            G.handCount[p] = handCount;                 // set the number of cards on hand
            memcpy(G.hand[p], estateArray, sizeof(int) * handCount); // set all the cards to estates
            
#if (NOISY_TEST == 1)
            printf("Score = %d\n", scoreFor(p,&G));
            printf("Expected = %d\n\n", handCount * estatePoints);
#endif
            assert(scoreFor(p,&G) == handCount * estatePoints);
            
// Test for garden points
#if (NOISY_TEST == 1)
			printf("Player %d with %d estate card(s).\n", p, handCount);
#endif
            memset(&G, 23, sizeof(struct gameState));   // clear the game state
            r = initializeGame(numPlayer, k, seed, &G); // initialize a new game
            G.handCount[p] = handCount;                 // set the number of cards on hand
            memcpy(G.hand[p], gardensArray, sizeof(int) * handCount); // set all the cards to estates
            
#if (NOISY_TEST == 1)
            printf("Score = %d\n", scoreFor(p,&G));
            printf("Expected = %d\n\n", handCount * gardenPoints);
#endif
            assert(scoreFor(p,&G) == handCount * gardenPoints);
            
        }
    }
    
    printf("All tests passed!\n");
    
    return 0;
}
